import { NgModule } from '@angular/core';
import { RouterModule, Routes, Router, NavigationEnd } from '@angular/router';

import { AuthGuard } from './auth/auth.guard';
import { LoginComponent } from './page/login/index.component';
import { RegisterComponent } from './page/register/index.component';
import { UpdatePwdComponent } from './userCenter/updatePwd';
import { WithdrawComponent } from './userCenter/withdraw';
import { UserInfoActivate } from './core/canActivate/userInfoActivate';
import { IndexActivate } from './core/canActivate/indexActivate';
import { GuideDetailActivate } from './core/canActivate/guideDetailActivate';
import { AgencyDetailActivate } from './core/canActivate/agencyDetailActivate';
import { UserDelComponent } from './userCenter/userDetail';
import { BankComponent } from './page/bank/index.component';
import { BaseMsgComponent } from './page/baseMsg/index.component';
import { WebsiteRedeployComponent } from './page/website-redeploy/index.component';
import { ConsumptionListComponent } from './page/consumptionList/index.component';
import { MyConsumptionListComponent } from './page/myConsumptionList/index.component';

const routes: Routes = [
	
	{ path: 'login', component: LoginComponent, canActivate: [AuthGuard] },
	{ path: 'register', component: RegisterComponent },
	{ path: 'bank', component: BankComponent },
	{ path: 'base', component: BaseMsgComponent },
	{ path: 'websiteRedeploy', component: WebsiteRedeployComponent },
	{ path: 'updatePwd/:type', component: UpdatePwdComponent },
	{ path: 'consumptionList', component: ConsumptionListComponent },
	{ path: 'myConsumptionList', component: MyConsumptionListComponent },

	{ path: 'withdraw', component: WithdrawComponent },
	{ path: 'userDel', component: UserDelComponent },
	{
		path: '**',
		redirectTo: 'login'
	}
];

@NgModule({
	exports: [RouterModule],
	imports: [RouterModule.forRoot(routes)],
	providers: [AuthGuard, UserInfoActivate, IndexActivate, GuideDetailActivate, AgencyDetailActivate],
	declarations: [],
})
export class AppRoutingModule {

	constructor(
        private router: Router
	) {
		this.router.events
		  .subscribe((event) => {
			  if(event instanceof NavigationEnd){
				window.scrollTo({top:0});
			}
		  });
	}

}
